package com.travel.service.impl;

import cn.hutool.core.lang.UUID;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qianfeng.util.ResultMsg;
import com.travel.entity.TbTrain;
import com.travel.entity.TbTripOrder;
import com.travel.mapper.TrainMapper;
import com.travel.mapper.TripMapper;
import com.travel.service.TripService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TripServiceImpl extends ServiceImpl<TripMapper, TbTripOrder> implements TripService {

    @Autowired
    TrainMapper trainMapper;

    @Override
    public ResultMsg insertOne(TbTripOrder triporderlist) {
        triporderlist.setTripTicketId(UUID.randomUUID().toString());
         boolean b = super.saveOrUpdate(triporderlist);
        return ResultMsg.success(b);
    }

    @Override
    public ResultMsg selectOne(String trainId) {

         QueryWrapper<TbTrain> wrapper = new QueryWrapper<>();
        wrapper.eq("train_id",trainId);
         TbTrain tbTrain = trainMapper.selectOne(wrapper);
        return ResultMsg.success(tbTrain);
    }

    @Override
    public ResultMsg findOne(String userCarid) {
         QueryWrapper<TbTripOrder> wrapper = new QueryWrapper<>();
         wrapper.eq("user_carid",userCarid);
         TbTripOrder tbTripOrder = super.getOne(wrapper);
        return ResultMsg.success(tbTripOrder);
    }
}
